import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)
import createPersistedState from "vuex-persistedstate"
import { getLogin } from "@/api/api.js"
export default new Vuex.Store({
  state: {
    token:''
  },
  mutations: {
    add(state,token){
      state.token=token
      localStorage.setItem('token',token)
    }
  },
  actions: {
    add({commit},userinfo){
      return new Promise((resolve,reject)=>{
      getLogin(userinfo).then(res=>{
        // console.log('登录成功结果',res);
        commit('add',res.data.token)
        resolve(res)
      }).catch(err=>{
          reject(err)
      })
  }) 
    }
    
  },
  modules: {
  },
  plugins: [createPersistedState()],
})
